package com.share.device.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.core.utils.DateUtils;
import com.share.device.domain.dto.StationDto;
//import com.share.device.repository.StationLocationRepository;
import com.share.device.domain.vo.StationVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.share.device.mapper.StationMapper;
import com.share.device.domain.Station;
import com.share.device.service.IStationService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 站点Service业务层处理
 *
 * @author ruoyi
 * @date 2025-06-24
 */
@Service
public class StationServiceImpl extends ServiceImpl<StationMapper, Station> implements IStationService
{
    @Autowired
    private StationMapper stationMapper;
//    @Autowired
//    private StationLocationRepository stationLocationRepository;

    @Transactional(rollbackFor = Exception.class)
    /**
     * 查询站点
     *
     * @param id 站点主键
     * @return 站点
     */
    @Override
    public Station selectStationById(Long id)
    {
        return stationMapper.selectStationById(id);
    }

    /**
     * 查询站点列表
     *
     * @param station 站点
     * @return 站点
     */
    @Override
    public List<Station> selectStationList(Station station)
    {
        return stationMapper.selectStationList(station);
    }

    /**
     * 新增站点
     *
     * @param station 站点
     * @return 结果
     */
    @Override
    public int insertStation(Station station)
    {
        station.setCreateTime(DateUtils.getNowDate());
        return stationMapper.insertStation(station);
    }

    /**
     * 修改站点
     *
     * @param station 站点
     * @return 结果
     */
    @Override
    public int updateStation(Station station)
    {
        station.setUpdateTime(DateUtils.getNowDate());
        return stationMapper.updateStation(station);
    }

    /**
     * 批量删除站点
     *
     * @param ids 需要删除的站点主键
     * @return 结果
     */
    @Override
    public int deleteStationByIds(Long[] ids)
    {
        return stationMapper.deleteStationByIds(ids);
    }

    /**
     * 删除站点信息
     *
     * @param id 站点主键
     * @return 结果
     */
    @Override
    public int deleteStationById(Long id)
    {
        return stationMapper.deleteStationById(id);
    }

    @Override
    public PageInfo<StationVo> getStationList(StationDto stationDto) {
        PageHelper.startPage(stationDto.getPageNum(), stationDto.getPageSize());
        List<StationVo> list = stationMapper.getStationList(stationDto);
        PageInfo<StationVo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
    /**
     * 新增站点 和添加MongDB
     */
//    @Autowired
//    private IStationService stationService;
//    @Override
//    public int addAndDB(StationDto stationDto) {
//        String provinceName = regionService.getNameByCode(stationDto.getProvinceCode());
//        String cityName = regionService.getNameByCode(stationDto.getCityCode());
//        String districtName = regionService.getNameByCode(stationDto.getDistrictCode());
//        station.setFullAddress(provinceName + cityName + districtName + stationDto.getAddress());
//        //拷贝
//        Station station = new Station();
//        BeanUtils.copyProperties(stationDto,station);
//        this.save(station);
//        //同步站点位置信息到MongoDB
//        StationLocation stationLocation = new StationLocation();
//        stationLocation.setId(ObjectId.get().toString());
//        stationLocation.setStationId(station.getId());
//        stationLocation.setLocation(new GeoJsonPoint(station.getLongitude().doubleValue(), station.getLatitude().doubleValue()));
//        stationLocation.setCreateTime(new Date());
//        stationLocationRepository.save(stationLocation);
//        return 1;
//    }
}
